import java.sql.*;

public class Mysqltwo {
    public static void main(String[] args) {
        Connection con;
        Statement sql;
        ResultSet rs;
        con = GetDBConnection.connectDB("world", "root", "");
        if (con == null) {
            return;
        }
        String sqlStr = "select Name,Population from country where Region = 'Middle East'";
        try {
            sql = con.createStatement();
            rs = sql.executeQuery(sqlStr);
            int total = 0;
            while (rs.next()) {
                String name = rs.getString(1);
                int population = rs.getInt(2);
                System.out.printf("%s的人口为%d\n", name, population);
                total += population;
            }
            System.out.println("中东国家的总人口为：" + total);
        } catch (SQLException e) {
            System.out.println("Error:" + e);
        }
    }
}


